home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / MPW Interfaces / CIncludes / fstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  3.0 KB  |  111 lines  |  [TEXT/MPS ]

  1. /*ident    "@(#)C++env:incl-master/const-headers/fstream.h    1.2" */
  2. /**************************************************************************
  3.                         Copyright (c) 1984 AT&T
  4.                           All Rights Reserved   
  5.  
  6.         THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  7.       
  8.         The copyright notice above does not evidence any        
  9.         actual or intended publication of such source code.
  10.  
  11. *****************************************************************************/
  12. #ifndef __FSTREAM__
  13. #define __FSTREAM__
  14.  
  15. #include <iostream.h>
  16.  
  17. class  filebuf : public streambuf {    /* a stream buffer for files */
  18. public:
  19.             filebuf() ;
  20.             filebuf(int fd);
  21.             filebuf(int fd, char*  p, int l) ;
  22.  
  23.     int        is_open() { return opened ; }
  24.     int        fd() { return xfd ; }
  25.     filebuf*    open(const char *name, int om/*, int prot=0664*/); // deleted for Macintosh
  26.     filebuf*    attach(int fd) ;
  27.     filebuf*     close() ;
  28.             ~filebuf() ;
  29. public: /* virtuals */
  30.     virtual int    overflow(int=EOF);
  31.     virtual int    underflow();
  32.     virtual int    sync() ;
  33.     virtual streampos
  34. #ifdef __ATT2_1
  35.             seekoff(streamoff,ios::seek_dir,int) ;
  36. #else  /*__ATT2_1*/
  37.             seekoff(streamoff,seek_dir,int) ;
  38. #endif /*__ATT2_1*/
  39.     virtual streambuf*
  40.             setbuf(char*  p, int len) ;
  41. protected:
  42.     int        xfd;    
  43.     int        mode ;
  44.     char        opened;
  45.     streampos    last_seek ;
  46.     char*         in_start;
  47.     int        last_op();
  48.     char        lahead[2] ;
  49. };
  50.  
  51. class fstreambase : virtual public ios { 
  52. public:
  53.             fstreambase() ;
  54.     
  55.             fstreambase(const char* name, 
  56.                     int mode/*,int prot=0664*/) ; // deleted for Macintosh
  57.             fstreambase(int fd) ;
  58.             fstreambase(int fd, char*  p, int l) ;
  59.             ~fstreambase() ;
  60.     void        open(const char* name, int mode/*, int prot=0664*/) ; // deleted for Macintosh
  61.     void        attach(int fd);
  62.     void        close() ;
  63.     void        setbuf(char*  p, int l) ;
  64.     filebuf*    rdbuf() { return &buf ; }
  65. private:
  66.     filebuf        buf ;
  67. protected:
  68.     void        verify(int) ;
  69. } ;
  70.  
  71. class ifstream : public fstreambase, public istream {
  72. public:
  73.             ifstream() ;
  74.             ifstream(const char* name, 
  75.                     int mode=ios::in /*,int prot=0664*/) ; // for Macintosh
  76.             ifstream(int fd) ;
  77.             ifstream(int fd, char*  p, int l) ;
  78.             ~ifstream() ;
  79.  
  80.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  81.     void        open(const char* name, int mode=ios::in/*, int prot=0664*/) ; // deleted for Macintosh
  82. } ;
  83.  
  84. class ofstream : public fstreambase, public ostream {
  85. public:
  86.             ofstream() ;
  87.             ofstream(const char* name, 
  88.                     int mode=ios::out/*,int prot=0664*/) ; // for Macintosh
  89.             ofstream(int fd) ;
  90.             ofstream(int fd, char*  p, int l) ;
  91.             ~ofstream() ;
  92.  
  93.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  94.     void        open(const char* name, int mode=ios::out /*, int prot=0664*/) ; // deleted for Macintosh
  95. } ;
  96.  
  97. class fstream : public fstreambase, public iostream {
  98. public:
  99.             fstream() ;
  100.     
  101.             fstream(const char* name, 
  102.                     int mode/*,int prot=0664*/) ; // for Macintosh
  103.             fstream(int fd) ;
  104.             fstream(int fd, char*  p, int l) ;
  105.             ~fstream() ;
  106.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  107.     void        open(const char* name, int mode/*, int prot=0664*/) ; // deleted for Macintosh
  108. } ;
  109.  
  110. #endif
  111.